package com.example.test;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.EntityManager;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import com.example.domain.Location;
import com.example.domain.User;
import com.example.repository.JPAUtil;

public class UserCrud {
	
	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
		
		
	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception {
	}

	@Before
	public void setUp() throws Exception {
	}

	@After
	public void tearDown() throws Exception {
	}

	@Test
	public void createUser() {
		JPAUtil.init();
		EntityManager em = JPAUtil.theEntityManagerFactory.createEntityManager();
		JPAUtil.ENTITY_MANAGERS.set(em);
		Location first = JPAUtil.findById(Location.class, 1L); 
		User one = new User();
		one.setName("samsung_vshop");
		one.setDeviceMac("2112-2558");
		JPAUtil.createEntity(one);
		
		Assert.assertNotNull(JPAUtil.findById(User.class, one.getId()));
	}

	@Test
	public void createLocations() {
		JPAUtil.init();
		EntityManager em = JPAUtil.theEntityManagerFactory.createEntityManager();
		JPAUtil.ENTITY_MANAGERS.set(em);
		User first = JPAUtil.findById(User.class, 1L); 
		Location one = new Location();
		one.setLatitude(new BigDecimal(100.0));
		one.setLongitude(new BigDecimal(123.2));
		one.setRoad(2);
		one.setStreetName("Kuila");
		one.setUser(first);
		JPAUtil.createEntity(one);
		
		Assert.assertNotNull(JPAUtil.findById(Location.class, one.getId()));
	}
	
	
}
